package src.entity;
import java.util.Date;

public class Achievement {
    private String name;
    private String content;
    private int condition; // 达成条件（如连续打卡14天）
    private String type; // 关联类型："habit" 或 "goal"
    private boolean isUnlocked;
    private Date unlockTime;

    public Achievement(String name, String content, int condition, String type) {
        this.name = name;
        this.content = content;
        this.condition = condition;
        this.type = type;
        this.isUnlocked = false;
    }

    // 检查习惯是否达成成就
    public boolean checkUnlock(Habit habit) {
        if (!type.equals("habit")) return false;
        if (habit.getContinuousDays() >= condition) {
            this.isUnlocked = true;
            this.unlockTime = new Date();
            return true;
        }
        return false;
    }

    // 检查目标是否达成成就
    public boolean checkUnlock(Goal goal) {
        if (!type.equals("goal")) return false;
        if (goal.isCompleted() && goal.getProgress() >= condition) {
            this.isUnlocked = true;
            this.unlockTime = new Date();
            return true;
        }
        return false;
    }

    // Getter & Setter
    public String getName() { return name; }
    public String getContent() { return content; }
    public boolean isUnlocked() { return isUnlocked; }
    public Date getUnlockTime() { return unlockTime; }
}